import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
@Auther: MFM
@Date: 2021/10/30 - 10 - 30 - 19:28 
@version: 1.0
*/

public class test {

    class ChildTread extends Thread{
        public ChildTread(String name){
            super(name);
        }

        public void run(){
            for (int i = 0; i < 200; i++) {
                System.out.println(this.getName()+"线程输出");
            }
        }
    }

    public void task(){
        new ChildTread("线程名字").start();

        for (int i = 0; i < 200; i++) {
            System.out.println(Thread.currentThread().getName()+"主线程输出");
        }
    }

    public static void main(String[] args) throws Exception{
        Callable<Integer> callable = () -> {
            int a = 3;
            int b = 5;
            Thread.sleep(3000);
            return a+b;
        };

        FutureTask<Integer> task = new FutureTask(callable);

        new Thread(task).start();
        Integer value =task.get(4000,TimeUnit.MILLISECONDS);
        System.out.println(value);
    }

}
